<?php
class v1_billboard{
    function index(){
		$data['basic']=$this->yum->config['Manage']['domain'].'?c=billboard&a=index';
		$params=array();$params['where']['A.locked !=']=10;
		if($this->yum->get('order',true)){
			$data['order']=$this->yum->get('order',true);$data['rule']=$this->yum->get('rule',true);
			if(in_array($data['order'],array('time'))&&in_array($data['rule'],array('desc','asc'))){
				$params['order']['A.'.$data['order']]=$data['rule'];
			}
		}else{
			$data['order']='time';$data['rule']='desc';
			$params['order']['A.'.$data['order']]=$data['rule'];
		}
		if($this->yum->get('date',true)){
			$data['date']=explode(',',$this->yum->get('date',true));
			if(count($data['date'])==2){
				$params['where']=array('A.time >='=>strtotime($data['date'][0]),'A.time <='=>strtotime($data['date'][1]));
				$data['basic'].='&date='.$data['date'][0].','.$data['date'][1];
			}
		}
		if($this->yum->get('search',true)){
			$data['search']=urldecode($this->yum->get('search',true));$data['tab']=$this->yum->get('tab',true);
			if($data['search']!=''){
				if($data['tab']=='mail'){
					$params['where']['B.mail LIKE']='%'.$data['search'].'%';
				}else if($data['tab']=='name'){
					$params['where']['A.name LIKE']='%'.$data['search'].'%';
				}else if($data['tab']=='id'){
					$params['where']['A.id LIKE']='%'.$data['search'].'%';
				}
				$data['basic'].='&tab='.$data['tab'];
				$data['basic'].='&search='.urlencode($data['search']);
			}
		}
		$board=$this->yum->model('billboard');
		$data['total']=$board->GFull(array('select'=>'COUNT(*) AS count','where'=>$params['where']));
		$data['total']=empty($data['total'])?0:$data['total'][0]['count'];
		$params['limit']=array(intval($this->yum->get('start')),15);
		$data['board']=$board->GFull($params);
		$name=array();
		foreach($data['board'] as $key=>$value){
			$name[]=$value['format'];$name[]=$value['usage'];$name[]=$value['modality'];
			$value['adcolumn']=explode(',',$value['adcolumn']);$value['adcolumn']=array_map('intval',$value['adcolumn']);
			$name=array_merge($name,$value['adcolumn']);
			$data['board'][$key]=$value;
		}
		$name=array_unique($name);
		if(empty($name)){
			$data['sort']=array();
		}else{
			$sort=$this->yum->model('sort');
			$data['sort']=$sort->GSort(array('select'=>'id,name','where'=>array('id IN'=>$name)));
		}
		$pagination=$this->yum->library('pagination',array('query_string'=>'start','base_url'=>$data['basic'].'&order='.$data['order'].'&rule='.$data['rule'],'total_rows'=>$data['total'],'per_page'=>15,'first_link'=>'首页','last_link'=>'末页','cur_tag_open'=>'<a href="#" class="active">','cur_tag_close'=>'</a>'));
		$data['pagination']=$pagination->create_links();
		$this->yum->set($data);
		$this->yum->view('index.php');
    }
    function locked(){
		$output=array('result'=>0,'msg'=>'');
		$board=$this->yum->model('billboard');
		$id=intval($this->yum->get('id',true));
		$locked=intval($this->yum->get('locked',true));
		if(is_array($id)){
			$affected=$board->UBoard(array('where'=>array('id IN'=>$id),'set'=>array('locked='=>$locked)));
			if($affected==0){
				$output['msg']='重复的数据提交.';
			}else{
				$output['result']=2;
			}
		}else{
			$affected=$board->UBoard(array('where'=>array('id='=>$id),'set'=>array('locked='=>$locked)));
			if($affected==1){
				$output['result']=5;
				$output['td']=array('offset'=>9,'data'=>array($locked==0?'正常':'删除'));
				$output['exec']=array('attr'=>array('mixed'=>'confirm:true,sub:{locked:'.($locked==0?10:0).'}'),'text'=>($locked==0?'删除':'正常'));
			}else{
				$output['msg']='状态已变更.';
			}
		}
		header('Content-Type:text/plain');
		echo json_encode($output);
    }
}
?>